package com.homework.controller;

import com.baomidou.mybatisplus.extension.api.R;
import com.homework.client.HwSearchClient;
import com.homework.search.dto.SearchResultDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Slf4j
@Controller
public class SearchController {

    @Autowired
    HwSearchClient hwSearchClient;

    @RequestMapping("/search")
    public String search(@RequestParam(defaultValue = "1") int current,
                         @RequestParam(defaultValue = "10")int size,
                         String keyword, Model model) {

        R<SearchResultDTO> results = hwSearchClient.search(current, size, keyword);

        log.info("搜索结果-----> {}",  results.getData());

        model.addAttribute("pageData", results.getData());

        return "search";
    }

}
